

// const state = JSON.parse(localStorage.getItem('counter_key'))||{count:1}
const state = {
    count:1,
    xxx:'abc'
}

const mutations = {
    increment(state,num){
        state.count += num
        // localStorage.setItem('counter_key',JSON.stringify(state))
    },
    decrement(state,num){
        state.count -= num
        // localStorage.setItem('counter_key',JSON.stringify(state))
    },

}
const actions = {
    incrementIfOdd(context,num){
        if(context.state.count%2===1){
            context.commit('increment',num)
        }
    },

    incrementAsync({commit},num){
        setTimeout(() => {
            commit('increment',num)
        }, 1000);
    }
}
const getters = {
    evenOrOdd(state){
        return state.count%2===1 ?'奇数' :'偶数'
    }
}

export default {
    namespaced:true,
    state,
    mutations,
    actions,
    getters
}